package com.rsk.api;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysCompanyResponsiblesService;
import com.rsk.service.SysCompanyTypesService;
import com.rsk.utils.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.QueryParam;

/**
 * 机构负责人
 * @author myr
 */

@RestController
@RequestMapping(value="/sys/comres")
public class SysCompanyResponsiblesApi {

    @Reference(interfaceClass = SysCompanyTypesService.class, protocol = "dubbo")
    private SysCompanyResponsiblesService sysCompanyResponsiblesService;


    /**
     * 删除机构负责人
     * @param id
     * @param Authorization
     * @return
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value = "/delSysCompanyResponsible")
    public Result<String> delSysCompanyResponsible(@QueryParam("id") Long id,
                                                   @RequestHeader("Authorization") String Authorization) {
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyResponsiblesService.delSysCompanyResponsible(id, operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }


    /**
     * 修改机构负责人
     * @param id
     * @param companyId
     * @param responsibleName
     * @param responsiblePhone
     * @param responsiblePost
     * @param Authorization
     * @return
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value = "/updateSysCompanysResponsible")
    public Result<String> updateSysCompanysResponsible(@QueryParam("id") Long id,
                                                       @QueryParam("companyId") String companyId,
                                                       @QueryParam("responsibleName") String responsibleName,
                                                       @QueryParam("responsiblePhone") String responsiblePhone,
                                                       @QueryParam("responsiblePost") String responsiblePost,
                                                       @RequestHeader("Authorization") String Authorization) {
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyResponsiblesService.updateSysCompanysResponsible(id, companyId, responsibleName,responsiblePhone,responsiblePost,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }


    /**
     * 新增机构负责人
     * @param id
     * @param companyId
     * @param responsibleName
     * @param responsiblePhone
     * @param responsiblePost
     * @param remarks
     * @param Authorization
     * @return
     *
     * 加字段 是否为主负责人  已加
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value = "/saveSysCompanysResponsible")
    public Result<String> saveSysCompanysResponsible(@QueryParam("id") Long id,
                                                     @QueryParam("companyId") Long companyId,
                                                     @QueryParam("contactsName") String responsibleName,
                                                     @QueryParam("contactsPhone") String responsiblePhone,
                                                     @QueryParam("contactsPost") String responsiblePost,
                                                     @QueryParam("remarks") Long remarks,
                                                     @QueryParam("mainResponsiable") int mainResponsiable,
                                                     @RequestHeader("Authorization") String Authorization) {
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyResponsiblesService.saveSysCompanysResponsible(id, companyId, responsibleName, responsiblePhone, responsiblePost, remarks,mainResponsiable,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }
}
